/*
 * @(#)ReplaceAllMethod.java $version 2010. 8. 11
 *
 * Copyright 2007-2010 NHN Corp. All rights Reserved. 
 * NHN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
 */
package com.nhncorp.usf.macro.method.component;

import java.util.List;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import freemarker.template.TemplateMethodModel;
import freemarker.template.TemplateModelException;

 /**
 * @author Web Platform Development Team
 */
public class ReplaceAllMethod implements TemplateMethodModel {
    Log log = LogFactory.getLog(ReplaceAllMethod.class);

    /**
     * @param args the arguments
     * @return the replace result value
     * @throws TemplateModelException the TemplateModelException
     */
    @SuppressWarnings("unchecked")
	public Object exec(List args) throws TemplateModelException {
        if (args.size() != 3) {
            throw new IllegalArgumentException("Arguments size must be three.");
        }

        String value = (String)args.get(0);
        String replace = (String)args.get(1);
        String with = (String)args.get(2);

        log.debug("value = " + value + " replace = " + replace + " with = " + with);

        value = value.replaceAll(replace, with);

        return value;
    }

}
